import cv2
from PIL import Image
import numpy as np
import torchvision
import torch

raw_img:np.ndarray=cv2.imread('../NCT-CRC-HE-100K/DEB/DEB-AAAPHWDG.tif',cv2.IMREAD_UNCHANGED)
print(type(raw_img))
print(raw_img.shape)
print('原图:',np.max(raw_img),np.min(raw_img),np.mean(raw_img))

my_transform=torchvision.transforms.ToTensor()
raw_arr:torch.Tensor=my_transform(raw_img)
print(raw_arr.shape)

print(torch.max(raw_arr),torch.min(raw_arr),torch.mean(raw_arr))

import torch.nn.functional as F

label1:torch.Tensor= torch.tensor([2,0,1,2],dtype=torch.long)
label2=torch.Tensor(
    [
        [0,0,1,],
        [1,0,0,],
        [0,1,0,],
        [0,0,1,],
    ]
)



pred:torch.Tensor=torch.Tensor([
    [1,2,3,],
    [3,2,1,],
    [6,7,8,],
    [5,4,3,],
])

print('softmax之后:',F.softmax(pred,dim=-1))
print(F.cross_entropy(pred,label1),F.cross_entropy(pred,label2))